//
//  SHStautsCell.swift
//  weibo1
//
//  Created by TownFish on 16/7/31.
//  Copyright © 2016年 TownFish. All rights reserved.
//

import UIKit
//重写UITableViewCell
class SHStautsCell: UITableViewCell {
    //定义一个ViewModel
    var statusViewModel: SHStatusViewModel? {
        didSet{
            //给原创微博赋值
            originalView.statusViewModel = statusViewModel
            let result = statusViewModel?.status?.retweeted_status
            print("转发微博模型:\(result)")
        }
    }
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 设置视图
    private func setupUI() {
        backgroundColor = RandomColor()
        
        //01-添加控件
        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(toolBarView)
        
        //02-添加约束
        //-01
        originalView.snp_makeConstraints { (make) -> Void in
            make.leading.top.trailing.equalTo(contentView)
            //当前约束已经在当前原创微博中约束
//            make.height.equalTo(50)
        }
        //-02
        retweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.leading.trailing.equalTo(contentView)
            //此约束已经在控件中约束
            //make.height.equalTo(50)
        }

        //-03
        toolBarView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetView.snp_bottom)
            make.leading.trailing.equalTo(contentView)
            make.height.equalTo(35)
        }
        
        //约束contentView
        contentView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.top.equalTo(self)
            make.bottom.equalTo(toolBarView)
        }
    }
    
    //MARK: - 懒加载控件
    //原创微博
    private lazy var originalView: SHStatusOriginalView = SHStatusOriginalView()
    //转发微博
    private lazy var retweetView: SHStatusRetweetView = SHStatusRetweetView()
    //底部视图
    private lazy var toolBarView: SHStatusToolBarView = SHStatusToolBarView()
}
